//
//  NoticeViewController.m
//  PlayBall
//
//  Created by admin on 14-7-30.
//
//

#import "NoticeViewController.h"
#import "JddGlobal.h"
#import "JddDefine.h"
#import "UIFitButton.h"
@interface NoticeViewController ()
{
    UIWebView *web;
}

@end

@implementation NoticeViewController
@synthesize webInfoId;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [MobClick beginLogPageView:@"Notice"];
    
//    //self.navigationItem.hidesBackButton = YES;
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"Notice"];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
//    //self.navigationItem.hidesBackButton = YES;
    [[JddGlobal sharedInstance].tabBar hide];
    [self createTitle];
    [self createWeb];
    [self createBackBtn];
}

- (void)createTitle
{
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 40)];
    lable.text = [self getTitle];
    lable.backgroundColor = [UIColor clearColor];
    [lable setFont:[UIFont systemFontOfSize:19]];
    lable.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = lable;
}
/*
 1	胜负彩	胜负彩
 2	四场进球彩	进球彩
 3	七星彩	七星彩
 5	双色球	双色球
 6	福彩3D	福彩3D
 9	体彩22选5	22选5
 13	七乐彩	七乐彩
 15	六场半全场	半全场
 19	任选九
 28      重庆时时彩
 29	时时乐	时时乐
 39	超级大乐透	大乐透
 45	足彩单场	单场
 61	江西时时彩	时时彩
 62	十一运夺金	十一运
 63	排列3	排列3
 64	排列5	排列5
 70	11选5	11选5
 71	山东群英会	群英会
 90	竞彩足球	竞彩足球
 91	竞彩篮球	竞彩篮球
 92	竞彩欧洲杯	
 93	竞彩奥运
 */
-(NSString*)getTitle{
    NSString *res;
    switch (webInfoId) {
        case LOTTERY_TYPE_ID_SF:{
            res = @"胜负彩";
        }
            break;
        case LOTTERY_TYPE_ID_4CJQC:{
            res = @"进球彩";
        }
            break;
        case 3:{
            res = @"七星彩";
        }
            break;
        case 5:{
            res = @"双色球";
        }
            break;
        case 6:{
            res = @"福彩3D";
        }
            break;
        case 9:{
            res = @"22选5";
        }
            break;
        case 13:{
            res = @"七乐彩";
        }
            break;
        case 15:{
            res = @"半全场";
        }
            break;
        case 19:{
            res = @"任选九";
        }
            break;
        case 28:{
            res = @"重庆时时彩";
        }
            break;
        case 29:{
            res = @"时时乐";
        }
            break;
        case 39:{
            res = @"大乐透";
        }
            break;
        case 45:{
            res = @"足球单场";
        }
            break;
        case 61:{
            res = @"时时彩";
        }
            break;
        case 62:{
            res = @"十一运夺金";
        }
            break;
        case 63:{
            res = @"排列3";
        }
            break;
        case 64:{
            res = @"排列5";
        }
            break;
        case 70:{
            res = @"11选5";
        }
            break;
        case 71:{
            res = @"群英会";
        }
            break;
        case 90:{
            res = @"竞彩足球";
        }
            break;
        case 91:{
            res = @"竞彩篮球";
        }
            break;
        case 92:{
            res = @"竞彩欧洲杯";
        }
            break;
        case 93:{
            res = @"竞彩奥运";
        }
            break;
        case -100:{
            res = @"合买";
        }
            break;
        default:
            res = @"资讯";
            break;
    }
    return res;
}

-(NSString*)getUrl{
    NSString *res;
    switch (webInfoId) {
        case LOTTERY_TYPE_ID_SF:{
            res = @"http://client.jiangduoduo.com/help/sfc.html";
        }
            break;
//        case LOTTERY_TYPE_ID_4CJQC:{
//            res = @"进球彩";
//        }
//            break;
        case 3:{
            res = @"http://client.jiangduoduo.com/help/qxc.html";
        }
            break;
        case 5:{
            res = @"http://client.jiangduoduo.com/help/ssq.html";
        }
            break;
        case 6:{
            res = @"http://client.jiangduoduo.com/help/3d.html";
        }
            break;
//        case 9:{
//            res = @"22选5";
//        }
//            break;
        case 13:{
            res = @"http://client.jiangduoduo.com/help/qlc.html";
        }
            break;
//        case 15:{
//            res = @"半全场";
//        }
//            break;
        case 19:{
            res = @"http://client.jiangduoduo.com/help/rx9c.html";
        }
            break;
        case 28:{
            res = @"http://client.jiangduoduo.com/help/cqssc.html";
        }
            break;
//        case 29:{
//            res = @"时时乐";
//        }
//            break;
        case 39:{
            res = @"http://client.jiangduoduo.com/help/dlt.html";
        }
            break;
        case 45:{
            res = @"http://client.jiangduoduo.com/help/bjdc.html";
        }
            break;
//        case 61:{
//            res = @"时时彩";
//        }
//            break;
        case 62:{
            res = @"http://client.jiangduoduo.com/help/syydj.html";
        }
            break;
        case 63:{
            res = @"http://client.jiangduoduo.com/help/pl3.html";
        }
            break;
        case 64:{
            res = @"http://client.jiangduoduo.com/help/pl5.html";
        }
            break;
        case 70:{
            res = @"http://client.jiangduoduo.com/help/11x5.html";
        }
            break;
//        case 71:{
//            res = @"群英会";
//        }
//            break;
        case 90:{
            res = @"http://client.jiangduoduo.com/help/jczq.html";
        }
            break;
        case 91:{
            res = @"http://client.jiangduoduo.com/help/jclq.html";
        }
            break;
//        case 92:{
//            res = @"竞彩欧洲杯";
//        }
//            break;
//        case 93:{
//            res = @"竞彩奥运";
//        }
//            break;
        case -100:{
            res = @"http://client.jiangduoduo.com/help/hmbz.html";
        }
            break;
        default:
            res = NoticeUrl;
            break;
    }
    return res;
}

- (void)createBackBtn
{
    UIImage * backImage = [UIImage imageNamed:@"back-btn"];
    UIButton * leftBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBackBtn setTitle:@"" forState:UIControlStateNormal];
    [leftBackBtn setTitle:@"" forState:UIControlStateHighlighted];
    [leftBackBtn setImage:backImage forState:UIControlStateNormal];
    [leftBackBtn setFrame:CGRectMake(0, 0, 30, 18)];
    [leftBackBtn addTarget:self action:@selector(leftBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBackBtn];
}


-(bool)checkDevice:(NSString*)name
{
    NSString* deviceType = [UIDevice currentDevice].model;
    NSRange range = [deviceType rangeOfString:name];
    return range.location != NSNotFound;
}

- (void)createWeb
{
//    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
    if([self checkDevice:@"iPhone"]){
        if(IOS7){
            web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64)];
        }else{
            web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-44)];
        }
    }else{
        web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    }
    
    
    web.delegate = self;
    web.scalesPageToFit = YES;
    
    NSArray *array = [web subviews];
    UIScrollView *scrollView =(UIScrollView *) [array objectAtIndex:0];
    scrollView.bounces = NO;
    
    NSURL *url = [NSURL URLWithString:[self getUrl]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [web loadRequest:request];
    [self.view addSubview:web];
    
}

#pragma mark 点击事件
- (void)leftBtnClicked:(UIButton *)button
{
    if (web.canGoBack) {
        if (web.loading) {
            [web stopLoading];
        }
        [web goBack];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
}

#pragma mark  WebViewDelegate的协议方法
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [JddCommonFunction setWaitingViewHidden:NO fromController:self];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
